package com.assistant.service.impl;

import com.assistant.mapper.PackagePostGetMapper;
import com.assistant.mapper.PersonalCentralMapper;
import com.assistant.pojo.Address;
import com.assistant.pojo.PackagePostGet;
import com.assistant.service.PersonalCentralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;


@Service
public class PersonalCentralServiceImpl implements PersonalCentralService {
    @Autowired
    private PersonalCentralMapper personalCentralMapper;
    @Autowired
    private PackagePostGetMapper packagePostGetMapper;


    /*
     * 更改个人信息
     * */
    public int updatePersonMessage(Address address) {
        Example example = new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id", address.getId());
        return personalCentralMapper.updateByExampleSelective(address, example);

    }


    /*
     * 新增个人的信息
     * */
    public int insertPersonMsg(Address address) {
        return personalCentralMapper.insertSelective(address);
    }

    /*
     * 查找某个人全部中心的信息
     * */
    public List<Address> showOneMsgs(String openid) {
        Example example = new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("open_id", openid);
        return personalCentralMapper.selectByExample(example);
    }

     /*
     * 查一个个人信息
     * */
    public Address showOneMsg(int address_id){
        return personalCentralMapper.selectByPrimaryKey(address_id);
    }


    /*
     * 需要open_id
     * 返回此用户发布或用户代拿的所有发布快递信息
     * */
   public List<PackagePostGet> packageGetPost(Map<String,String> map){
       Example example = new Example(PackagePostGet.class);
       Example.Criteria criteria = example.createCriteria();
       System.out.println(map);
       if (map.get("package_id")!=null){
           criteria.andEqualTo("package_id",map.get("package_id"));
       }
       if (map.get("getter_id")!=null){
           criteria.andEqualTo("getter_id",map.get("getter_id"));
       }
       if (map.get("poster_id")!=null){
           criteria.andEqualTo("poster_id",map.get("poster_id"));
       }
       if (map.get("status")!=null){
           criteria.andEqualTo("status_g",map.get("status"));
       }

       return packagePostGetMapper.selectByExample(example);
   }

}
